#!/bin/sh


echo "" > /etc/hostname

hostname 

cat > /etc/hosts << EOF
127.0.0.1   snapshothost  localhost localhost.localdomain
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF


apt-get update >/dev/null 2>/dev/null
apt-get -y install puppet >/dev/null 2>/dev/null


cat > /etc/puppet/puppet.conf << EOF
[main]
vardir = /var/lib/puppet
logdir = /var/log/puppet
rundir = /var/run/puppet
ssldir = \$vardir/ssl

[agent]
pluginsync      = true
report          = true
ca_server       = 
certname        = snapshothost
environment     = 
server          = 
EOF

/usr/bin/puppet agent --config /etc/puppet/puppet.conf -o --tags no_such_tag --server  --no-daemonize
if [ -x /usr/bin/curl ]; then
  /usr/bin/curl -o /dev/null --noproxy \* -H 'Content-Type: text/plain' --silent 'http://foreman.some.host.fqdn/unattended/built'
elif [ -x /usr/bin/wget ]; then
  /usr/bin/wget -q -O /dev/null --no-proxy --method POST --header 'Content-Type: text/plain' 'http://foreman.some.host.fqdn/unattended/built'
else
  wget -q -O /dev/null --header 'Content-Type: text/plain' 'http://foreman.some.host.fqdn/unattended/built'
fi

/sbin/chkconfig puppetd on

PATH=/usr/bin:/usr/sbin:/bin:/sbin:$PATH shutdown -r +1

exit 0
